package com.yuwei.patrol.view

import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.yuwei.base.BaseActivity
import com.yuwei.base.path.RouterPath
import com.yuwei.patrol.adapter.PatrolAdapter
import com.yuwei.patrol.databinding.ActivityPatrolBinding
import com.yuwei.patrol.viewmodel.PatrolViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.MODULE_PATROL_ACTIVITY)
class PatrolActivity : BaseActivity<ActivityPatrolBinding,PatrolViewModel>() {
    private val patrolAdapter = PatrolAdapter()
    override fun initView() {
        vm.getPatrolList()
        vm.getPatrolPoints()
        binding.patrolRv.adapter = patrolAdapter
        binding.patrolRv.layoutManager = LinearLayoutManager(this)
        binding.patrolBack.setOnClickListener {
            finish()
        }
        binding.patrolTopBarAdd.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_EDIT_PATROL_ACTIVITY).navigation()
        }
    }

    override fun initData() {
        vm.getPatrolSuccess.observe(this){
            Log.d("TAG", "initDataPatrol: ${it[0].patrolPerson}")
            patrolAdapter.data.addAll(it)
            patrolAdapter.notifyDataSetChanged()
        }
        vm.getPatrolPointsSuccess.observe(this){
            Log.d("TAG", "initDataPatrolPoints: ${it[0].pointLocation}")
            patrolAdapter.setList(it)
        }
    }

}